VERSION 5.00
Object = "{B3FB64BF-91F9-11D7-A482-0008A14158BC}#2.22#0"; "ITGControls.ocx"
Begin VB.Form frmToolClosing 
   BackColor       =   &H00F7D9C2&
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Monthly Closing"
   ClientHeight    =   2745
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   3435
   ControlBox      =   0   'False
   BeginProperty Font 
      Name            =   "Tahoma"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   2745
   ScaleWidth      =   3435
   Begin VB.ComboBox cboModule 
      Appearance      =   0  'Flat
      BackColor       =   &H00FFFFFF&
      Height          =   315
      ItemData        =   "frmToolClosing.frx":0000
      Left            =   1320
      List            =   "frmToolClosing.frx":000A
      Style           =   2  'Dropdown List
      TabIndex        =   12
      Top             =   135
      Width           =   1485
   End
   Begin ITGControls.ITGCommandButton cmdCancel 
      Height          =   345
      Left            =   1920
      TabIndex        =   3
      Top             =   2205
      Width           =   1020
      _ExtentX        =   1799
      _ExtentY        =   609
      BackColor       =   16243138
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Caption         =   "&Cancel"
   End
   Begin ITGControls.ITGCommandButton cmdOK 
      Height          =   345
      Left            =   585
      TabIndex        =   2
      Top             =   2205
      Width           =   1035
      _ExtentX        =   1826
      _ExtentY        =   609
      BackColor       =   16243138
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Caption         =   "&OK"
   End
   Begin ITGControls.ITGTextBox txtModule 
      Height          =   285
      Left            =   1320
      TabIndex        =   13
      Tag             =   "cboType"
      Top             =   120
      Visible         =   0   'False
      Width           =   1485
      _ExtentX        =   2514
      _ExtentY        =   503
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Mandatory       =   -1  'True
      Label           =   "Invoice Type"
      BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      LabelWidth      =   0
      TextBoxWidth    =   1425
   End
   Begin VB.Frame fraYearEnd 
      BackColor       =   &H00F7D9C2&
      Height          =   1560
      Left            =   120
      TabIndex        =   6
      Top             =   525
      Width           =   3135
      Begin VB.Frame Frame4 
         Appearance      =   0  'Flat
         BackColor       =   &H00F7D9C2&
         ForeColor       =   &H80000008&
         Height          =   1365
         Left            =   75
         TabIndex        =   7
         Top             =   120
         Width           =   2985
         Begin VB.CommandButton Command1 
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   270
            Left            =   2505
            Picture         =   "frmToolClosing.frx":0030
            Style           =   1  'Graphical
            TabIndex        =   17
            Top             =   600
            Width           =   330
         End
         Begin ITGControls.ITGDateBox dtbDate 
            Height          =   285
            Left            =   1380
            TabIndex        =   10
            Top             =   285
            Width           =   1455
            _ExtentX        =   2566
            _ExtentY        =   503
            BackColor       =   -2147483643
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Text            =   ""
            BackColor       =   -2147483643
         End
         Begin ITGControls.ITGTextBox txtEarnings 
            Height          =   285
            Left            =   30
            TabIndex        =   8
            Top             =   885
            Width           =   2820
            _ExtentX        =   4763
            _ExtentY        =   503
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Locked          =   -1  'True
            Label           =   "Earnings"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1300
            TextBoxWidth    =   1460
         End
         Begin ITGControls.ITGTextBox txtAccount 
            Height          =   285
            Left            =   15
            TabIndex        =   9
            Top             =   585
            Width           =   2445
            _ExtentX        =   4101
            _ExtentY        =   503
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Locked          =   -1  'True
            Label           =   "Account"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1300
            TextBoxWidth    =   1085
         End
         Begin VB.Label lblYE 
            BackColor       =   &H00F7D9C2&
            Caption         =   "Date"
            Height          =   255
            Left            =   75
            TabIndex        =   11
            Top             =   315
            Width           =   1245
         End
      End
   End
   Begin VB.Frame fraMonthly 
      BackColor       =   &H00F7D9C2&
      Height          =   1530
      Left            =   120
      TabIndex        =   4
      Top             =   540
      Width           =   3120
      Begin VB.Frame Frame2 
         Appearance      =   0  'Flat
         BackColor       =   &H00F7D9C2&
         Caption         =   " Date Range "
         ForeColor       =   &H80000008&
         Height          =   1260
         Left            =   60
         TabIndex        =   5
         Top             =   150
         Width           =   2985
         Begin ITGControls.ITGDateBox dtbTo 
            Height          =   285
            Left            =   1170
            TabIndex        =   1
            Top             =   675
            Width           =   1305
            _ExtentX        =   2302
            _ExtentY        =   503
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Text            =   ""
            SendKeysTab     =   -1  'True
         End
         Begin ITGControls.ITGDateBox dtbFrom 
            Height          =   285
            Left            =   1170
            TabIndex        =   0
            Top             =   375
            Width           =   1305
            _ExtentX        =   2302
            _ExtentY        =   503
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Text            =   ""
            SendKeysTab     =   -1  'True
         End
         Begin VB.Label Label2 
            BackColor       =   &H00F7D9C2&
            Caption         =   "From"
            Height          =   255
            Left            =   600
            TabIndex        =   16
            Top             =   405
            Width           =   390
         End
         Begin VB.Label Label1 
            BackColor       =   &H00F7D9C2&
            Caption         =   "To"
            Height          =   255
            Left            =   585
            TabIndex        =   15
            Top             =   690
            Width           =   390
         End
      End
   End
   Begin VB.Label lblModule 
      BackColor       =   &H00F7D9C2&
      Caption         =   "Module"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   9.75
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   360
      TabIndex        =   14
      Top             =   120
      Width           =   1575
   End
End
Attribute VB_Name = "frmToolClosing"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'IT Group Inc. 2005.04.25

Option Explicit

Enum eToolType
    e_Closing
    e_Recompute
    e_Posting
End Enum

Public mToolType As eToolType
Public rsclosing As New Recordset
Public sBit As String

'Security Acess Level variables
Public lACNew As Boolean
Public lACEdit As Boolean
Public lACDelete As Boolean
Public lACPost As Boolean
Public lACCancel As Boolean
Public lACPrint As Boolean
Private Sub cboModule_Click()
    txtModule = Trim(cboModule)
    If cboModule.Text = "Closing" Then
        RepName = "Closing"
        fraMonthly.Visible = True
        fraYearEnd.Visible = False
    ElseIf cboModule.Text = "Recompute" Then
        RepName = "Recompute"
        fraMonthly.Visible = True
        fraYearEnd.Visible = False
    ElseIf cboModule.Text = "Year-End" Then
        RepName = "Year-End"
        fraMonthly.Visible = False
        fraYearEnd.Visible = True
        dtbDate.Text = Format(GetValueFrTable("cValue", "SYSTEM_OPTION", "cCode = 'MTDDATETO'"), "mm/dd/yyyy")
        'txtAccount.SetFocus
        Dim rs As New Recordset
        sSQL = "select  sum(nInitial) as nAmount from (select  nInitial From account where   cAcctNo='4' AND cCompanyID = '" & COID & "' Union All select -1*nInitial From account where   cAcctNo='5' AND cCompanyID = '" & COID & "') A"
        rs.Open sSQL, cn, adOpenForwardOnly, adLockReadOnly
        txtEarnings = Format(IIf(IsNull(rs!nAmount), 0, rs!nAmount), "###0.#0")
        rs.Close
    Else: RepName = ""
    End If
End Sub

Private Sub Command1_Click()
            frmITGPicker.zType = QAccounts
            frmITGPicker.Show vbModal
            If Trim(frmITGPicker.zCode) = "" Then Exit Sub
            txtAccount.Text = frmITGPicker.zCode & ""
End Sub

Private Sub cboModule_KeyPress(KeyAscii As Integer)
    SendKeysTab KeyAscii
End Sub

Private Sub cmdCancel_Click()
    Unload Me
End Sub

Private Sub txtModule_Change()
    If Trim(txtModule) <> "" Or txtModule <> vbNullString Then
        cboModule = Trim(txtModule)
        If RepName = "Closing" Then
            dtbFrom.Text = Format(GetValueFrTable("cValue", "SYSTEM_OPTION", "cCode = 'MTDDATEFROM'"), "mm/dd/yyyy")
            dtbTo.Text = Format(GetValueFrTable("cValue", "SYSTEM_OPTION", "cCode = 'MTDDATETO'"), "mm/dd/yyyy")
        ElseIf RepName = "Recompute" Then
        ElseIf RepName = "Year-End" Then
   '        FraYear.Visible = True
            dtbDate.Text = Format(GetValueFrTable("cValue", "SYSTEM_OPTION", "cCode = 'MTDDATETO'"), "mm/dd/yyyy")
            'txtAccount.SetFocus
            sSQL = "select  sum(nInitial) as nAmount from (select  nInitial From account where   cAcctNo='4' AND cCompanyID = '" & COID & "' Union All select -1*nInitial From account where   cAcctNo='5' AND cCompanyID = '" & COID & "') A"
            rsclosing.Open sSQL, cn, adOpenForwardOnly, adLockReadOnly
            txtEarnings = Format(IIf(IsNull(rsclosing!nAmount), 0, rsclosing!nAmount), "###0.#0")
            rsclosing.Close
        Else
            RepName = " "
        End If
    Else
        cboModule.ListIndex = -1
    End If
End Sub


Private Sub cmdOK_Click()
On Error GoTo ErrorHandler
    If RepName = "Closing" Then
        If MsgBox("Are you sure you want to close transactions?", vbQuestion + vbYesNo, "ComUnion") = vbNo Then Exit Sub
            Dim cmdClosing As ADODB.Command
            Set cmdClosing = New ADODB.Command
            With cmdClosing
                .ActiveConnection = cn
                .CommandTimeout = 1000
                .CommandText = "ClosingModule"
                .CommandType = adCmdStoredProc
                .Parameters("@tcCompanyID") = COID
                .Parameters("@tdFrom") = Trim(dtbFrom.Text)
                .Parameters("@tdTo") = Trim(dtbTo.Text)
                .Execute
            End With
            Set cmdClosing = Nothing
            MsgBox "Current transactions successfully closed!", vbInformation
    ElseIf RepName = "Recompute" Then
        If MsgBox("Are you sure you want to recompute transactions?", vbQuestion + vbYesNo, "ComUnion") = vbNo Then Exit Sub
            Dim cmdRecompute As ADODB.Command
            Set cmdRecompute = New ADODB.Command
            With cmdRecompute
                .ActiveConnection = cn
                .CommandTimeout = 1000
                .CommandText = "SP_CostRecompute"
                .CommandType = adCmdStoredProc
                .Parameters("@cCompanyID") = COID
                .Parameters("@dDateFrom") = Trim(dtbFrom.Text)
                .Parameters("@dDateTo") = Trim(dtbTo.Text)
                .Execute
            End With
            Set cmdRecompute = Nothing
            MsgBox "Current transactions successfully computed!", vbInformation
    ElseIf RepName = "Year-End" Then
            If Trim(dtbDate.Text) = "__/__/____" Then
                MsgBox "Please specify Year-end Date to Close.", vbInformation, msgTtl
            ElseIf Trim(txtAccount) = "" Then
                MsgBox "Please specify account.", vbInformation, msgTtl
            Else
                If MsgBox("Are you sure you want to close the year-end book?", vbQuestion + vbYesNo, msgTtl) = vbNo Then Exit Sub
                Dim cmdYearend As ADODB.Command
                Set cmdYearend = New ADODB.Command
                With cmdYearend
                    .ActiveConnection = cn
                    .CommandTimeout = 2000
                    .CommandText = "sp_YearendClosing"
                    .CommandType = adCmdStoredProc
                    .Parameters("@COID") = COID
                    .Parameters("@dDate") = CStr(Trim(dtbDate.Text))
                    .Parameters("@cAcctNo") = Trim(txtAccount)
                    .Execute
                End With
                Set cmdYearend = Nothing
                MsgBox "Year Closed!", vbInformation, msgTtl
            End If
    End If
ErrorHandler:
    If err.Number = -2147217900 Then
        MsgBox err.Description, vbCritical
    End If
End Sub

Private Sub Form_Load()
    Set FrmName = Me
    
    AcessBit Me, GetValueFrTable("AccessLevel", "SEC_ACCESSLEVEL", "RoleID = '" & SecUserRole & "' AND [Module] = 'ST06'")
    
    Call LoadComboValues(cboModule, "cValue", "PARAMETER_SYSTEM", "WHERE cType = 'CL_MOD'")

    RepName = " "
    txtModule.Text = "Closing"
    RepName = "Closing"
    TBBitReload
End Sub

Public Sub TBBitReload()
    Set FrmName = Me
    BitVisible ITGLedgerMain.tbrMain, True, True
    sBit = "0000000000001000"
    BitReload ITGLedgerMain, Me, ITGLedgerMain.tbrMain, sBit
End Sub

Public Sub TBCloseWindow()
    Unload Me
End Sub

Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next
    
    CloseMenuTab ITGLedgerMain
    
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , , , , , , , True
    BitVisible ITGLedgerMain.tbrMain
    ITGLedgerMain.tbrMain.Buttons("btnFind").ButtonMenus("btnFindP").Enabled = False

    Set frmToolClosing = Nothing
    
    lCloseWindow = True

End Sub
